/*
 * @lc app=leetcode.cn id=2073 lang=golang
 *
 * [2073] 买票需要的时间
 */
package Solutions

// @lc code=start
func timeRequiredToBuy(tickets []int, k int) int {
	var ans = 0
	for i := 0; i < len(tickets); i++ {
		if i > k {
			ans += min__time(tickets[i], tickets[k]-1)
		} else {
			ans += min__time(tickets[i], tickets[k])
		}

	}
	return ans
}

func min__time(i, j int) int {
	if i < j {
		return i
	}
	return j
}

// @lc code=end
